<template>
  <div>
    <slot name="prefix"></slot>
    <input type="text" v-model="title"> <button @click="add">{{ btnText }}</button>
  </div>
</template>
<script>
import axios from 'axios';

const request = axios.create({
  baseURL: 'http://127.0.0.1:8081'
});
export default {
  props: {
    btnText: { type: String, default: '添加' }
  },
  data() {
    return {
      title: '',
    };
  },
  methods: {
    async add() {
      if (this.title === '') return;
      await request.post('/lists', {
        status: 1,
        title: this.title
      });
      this.title = '';
      // 添加成功
      this.$emit('add-success');
    }
  }
};
</script>